/**
 * @file:          DataSampler.h
 * @brief:
 * @details:
 * @author:        wjh
 * @date created:  2024.12.09
 * @version:       1.0.0
 * @par copyright (c):
 *
 * @par history (desc):
 *   version:1.0.0, wjh, 2024.12.09,11:53:41
 */

#ifndef _DATASAMPLER_H_
#define _DATASAMPLER_H_

/* Include Files **************************************************************/
#include "Datatype.h"

/* Macro Definition ***********************************************************/

/* Data Type Define ***********************************************************/
enum DataSampler_Mode_Enum
{
    DataSampler_Mode_SoftwareTrig = 0,
    DataSampler_Mode_IOTrig_Rising = 1,
    DataSampler_Mode_IOTrig_Falling = 2,
};

enum DataSampler_DataType_Enum
{
    DataSampler_DataType_uint8 = 0,
    DataSampler_DataType_int8 = 1,
    DataSampler_DataType_uint16 = 2,
    DataSampler_DataType_int16 = 3,
    DataSampler_DataType_uint32 = 4,
    DataSampler_DataType_int32 = 5,
    DataSampler_DataType_float = 6,
    DataSampler_DataType_double = 7,
};

typedef struct DataSampler
{
    /* public data */

    uint32_t param_data_length;         /* 采样长度 */
    uint16_t param_sample_interval;     /* 采样间隔周期 */
    uint16_t param_print_interval;      /* 打印间隔周期 */
    uint16_t param_sample_mode;         /* 采样模式 */
    uint16_t param_io_trig_delay_count; /* IO触发延时周期数 */
    uint16_t param_auto_print;          /* 采集完后是否自动打印 */
    uint16_t param_data_type;           /* 采样数据类型 */
    void *in_data;                      /* 采样数据配置，指向被采样数据 */
    uint16_t *in_io_bind;               /* 绑定用于触发的IO变量 */

    uint16_t in_io_level;
    uint16_t io_level_last;

    uint16_t in_start; /* 采样开始控制，置1则开始采样 */
    uint16_t running;
    uint16_t finished;

    uint16_t io_trig_start; /* io电平变化触发点 */
    uint16_t io_trig_running;
    uint16_t io_trig_count;

    uint16_t in_print_start; /* 数据打印开始控制 */
    uint16_t print_running;
    uint16_t print_finished;

    void *data_buffer;
    uint32_t index;
    uint32_t count;

    /* private data */

    /* public method */
    void (*Init)(struct DataSampler *self);
    uint16_t (*Run)(struct DataSampler *self);
    void (*UpdateParam)(struct DataSampler *self);
    uint16_t (*PrintData)(struct DataSampler *self);

    /* private method */

} DataSampler;

/* Variable Declare ***********************************************************/

/* Function Declare ***********************************************************/
void DataSampler_Init(struct DataSampler *self);
uint16_t DataSampler_Run(struct DataSampler *self);
void DataSampler_UpdateParam(struct DataSampler *self);
uint16_t DataSampler_PrintData(struct DataSampler *self);

#endif